package org.vectrics.common.db;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author MMoore
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class DataUtils {
	public static Collection removeVoided(Collection elements) {
		Collection newElements = new HashSet();
		Iterator iter = elements.iterator();
		while (iter.hasNext()) {
			Voidable voidable = (Voidable)iter.next();
			if (voidable.getVoided() == true) {
			} else {
				newElements.add(voidable);
			}
		}
		
		return(newElements);
	}
	
	public static Set removeVoided(Set elements) {
		Set resultSet = new HashSet();
		resultSet.addAll(elements);
		Set deleteList = new HashSet();
		Iterator iter = elements.iterator();
		while (iter.hasNext()) {
			Voidable voidable = (Voidable)iter.next();
			if (voidable.getVoided() == true) {
				deleteList.add(voidable);
			}
		}
		
		iter = deleteList.iterator();
		while (iter.hasNext()) {
			Object obj = (Object)iter.next();
			resultSet.remove(obj);
		}
		return(resultSet);
	}
}
